<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>03-字符出现次数</title>
</head>
<body>
  <script>
    function maxChar(str) {
      const obj = {}
      for(let i = 0; i < str.length; i++) {
        obj[str[i]] ? obj[str[i]]++ : (obj[str[i]] = 1)
      }
      
      let max = {
        char: undefined,
        count: 0
      }

      // Object.keys(obj).forEach(key => {
      //   if(obj[key] > max.count) {
      //     max.char = key
      //     max.count = obj[key]
      //   }
      // })
      for(key in obj) {
        if(obj[key] > max.count) {
          max.char = key
          max.count = obj[key]
        }
      }
      return max
    }
    console.log(maxChar('000111'))
   
  </script>
</body>
</html>